from django.shortcuts import render,HttpResponse
import json
from .models import userdata
# Create your views here.

def index(request):
    return render(request,'postdata.html')

def jsondata(request):
    if (request.method == 'POST'):
        jsondata = request.POST['data']
        json_result = json.loads(jsondata)
        user = userdata()
        user.name = json_result["name"]
        user.tel = json_result["telephone"]
        user.userid = json_result["uUserId"]
        user.picture = json_result["faceImage"]
        user.save()
        return HttpResponse('ok')
        # print("the POST method")
        # postBody=request.POST
        # concat = request.POST
        # postBody = request.body
        # print(concat)
        # print(type(postBody))
        # print(postBody)
        # json_result = json.loads(postBody)
        # print(json_result)